using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;

namespace octalforty.Componento.Core.ObjectModel
{
    [DebuggerDisplay("{Name,nq} {Version,nq}")]
    public class PackageManifest
    {
        public string Name
        { get; private set; }

        public Version Version
        { get; private set; }

        public string Description
        { get; private set; }

        public Uri ProjectUri
        { get; private set; }
        
        public ReadOnlyCollection<PackageReference> Dependencies
        { get; private set; }

        public ReadOnlyCollection<PackageResource> Resources
        { get; private set; }

        public ReadOnlyCollection<PlatformVersion> SupportedPlatforms
        { get; private set; }

        public PackageManifest()
        {
        }

        public PackageManifest(string name, Version version, string description) :
            this(name, version, description, null, null, null, null)
        {
        }

        public PackageManifest(string name, Version version, string description, Uri projectUri, 
            IEnumerable<PackageReference> dependencies, IEnumerable<PackageResource> resources,
            IEnumerable<PlatformVersion> supportedPlatforms)
        {
            Name = name;
            Version = version;
            Description = description;
            ProjectUri = projectUri;

            Dependencies = new ReadOnlyCollection<PackageReference>(new List<PackageReference>(dependencies ?? new PackageReference[] { }));
            Resources = new ReadOnlyCollection<PackageResource>(new List<PackageResource>(resources ?? new PackageResource[] { }));
            SupportedPlatforms = new ReadOnlyCollection<PlatformVersion>(new List<PlatformVersion>(supportedPlatforms ?? new PlatformVersion[] { }));
        }

        internal void AddSupportedPlatform(PlatformVersion platformVersion)
        {
            SupportedPlatforms = new ReadOnlyCollection<PlatformVersion>(
                SupportedPlatforms.Union(new[] { platformVersion }).ToList());
        }
    }
}